﻿using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class BuffEffective_ReplaceSkill : BuffEffective
    {
        protected override void OnInitProperty(BuffEffectData rData, BuffComponent rTarget)
        {
            base.OnInitProperty(rData, rTarget);
            if (rData.param.Count > 1)
            {
                var rConfigData = new ConfigData()
                {
                    skillID = rData.param[0],
                    replaceID = rData.param[1]
                };
                rData.userData = rConfigData;
            }
        }

        protected override void OnActive(BuffEffectContext rContext, BuffEffectData rConfig, int nRuntimeParam)
        {
            base.OnActive(rContext, rConfig, nRuntimeParam);
            if (rConfig.userData is ConfigData rConfigData)
            {
                var rTarget = rContext.buff.target;
                rTarget.replaceSkill[rConfigData.skillID] = rConfigData.replaceID;
            }
        }

        protected override void OnDeActive(BuffEffectContext rContext, BuffEffectData rConfig)
        {
            base.OnDeActive(rContext, rConfig);
            if (rConfig.userData is ConfigData rConfigData)
            {
                var rTarget = rContext.buff.target;
                rTarget.replaceSkill.Remove(rConfigData.skillID);
            }
        }

#if UNITY_EDITOR
        public override string ToString(BuffEffectData rConfig)
        {
            var rConfigData = rConfig.userData as ConfigData;
            return $"替换{rConfigData.skillID}为{rConfigData.replaceID}";
        }
#endif


        public class ConfigData : BuffEffectiveConfig
        {
            public int skillID;
            public int replaceID;
        }
    }
}